/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package net.risesoft.risebi.collection.web.admin;

import net.risesoft.risebi.collection.model.User;
import net.risesoft.risebi.collection.service.ShortMessageManager;
import net.risesoft.risebi.collection.web.BaseAction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 * 一般的流程转向action
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Namespace("/admin/IndexAction")
public class IndexAction extends BaseAction {	
	private static final long serialVersionUID = -1256394441467545449L;
	
	private int newInboxCount;
	private String initialPassword;
	private String newShortMessage;
	private String username;
	private String currentService;
	private String currentApp;
	
	private ShortMessageManager shortMessageManager;

	@Action(value="index",
			results={@Result(name="success", location="/admin/index.jsp")}
			)
	public String index() throws Exception {
		this.username = this.getSessionUser().getName();
		if(this.getDefaultService()==null){
			this.currentService = "";
		}else{
			this.currentService = this.getDefaultService().getName();
		}
		
		if(this.getDefaultApp()==null){
			this.currentApp = "";
		}else{
			this.currentApp = this.getDefaultApp().getChineseName();
		}
		
		User user = this.getSessionUser();
		
//    	获得收件箱新的短信
    	newInboxCount = shortMessageManager.getInboxCountByUserGuid(user.getGuid(),false);
    	
    	if(newInboxCount>0){
    		newShortMessage = "<a href='javascript:void(0)' class='a02' onclick='gotoInbox();'>您有新的短信：<span style='color:red' id='newShortMessageCount'> "+newInboxCount+"</span>条<img id='newShortMessageImage' src='"+this.getContextPath()+"/images/system/newpm.gif'></a>，";
    	}else{
    		newShortMessage = "<a href='javascript:void(0)' class='a02' onclick='gotoInbox();'>您有新的短信：<span style='color:red'> "+newInboxCount+"</span>条</a>，";
    	}
    	
//    	判断是否需要更改密码
    	if(user.judgeInitialPassword()){
    		initialPassword = "<span class='mysize' id='initialPasswordDiv'><img src='"+this.getContextPath()+"/images/system/beep.gif' height='14'><a href='javascript:void(0)' class='a01' onclick='changePs();'>密码太简单，建议您修改</a></span>";
    	}
		
		return SUCCESS;
	}
	
	@Action(value="module",
			results={@Result(name="success", location="/admin/bottom.jsp")}
			)
	public String module() throws Exception {
		
		return SUCCESS;
	}
	
	@Action(value="blank",
			results={@Result(name="success", location="/blank.jsp")}
			)
	public String blank() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="welcome",
			results={@Result(name="success", location="/welcome.jsp")}
			)
	public String welcome() throws Exception {
		return SUCCESS;
	}
	
	public void setShortMessageManager(ShortMessageManager shortMessageManager) {
		this.shortMessageManager = shortMessageManager;
	}

	public int getNewInboxCount() {
		return newInboxCount;
	}

	public void setNewInboxCount(int newInboxCount) {
		this.newInboxCount = newInboxCount;
	}

	public String getInitialPassword() {
		return initialPassword;
	}

	public void setInitialPassword(String initialPassword) {
		this.initialPassword = initialPassword;
	}

	public String getNewShortMessage() {
		return newShortMessage;
	}

	public void setNewShortMessage(String newShortMessage) {
		this.newShortMessage = newShortMessage;
	}

	public String getUsername() {
		return username;
	}

	public String getCurrentService() {
		return currentService;
	}

	public String getCurrentApp() {
		return currentApp;
	}

}
